using System;
using System.ComponentModel;
using System.Web.Services;


namespace Agron.Web.Services
{
    /// <summary>
    /// A <see cref="WebService"/> that provides address information functions.
    /// </summary>
    [WebService(Namespace = "http://services.udlap.mx/Agron/AddressInfoService.asmx")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class AddressInfoService : System.Web.Services.WebService
    {
        /// <summary>
        /// Gets the IP address of the caller.
        /// </summary>
        /// <returns>
        /// A <see cref="string"/> containing the IP Address of the caller.
        /// </returns>
        [Description("Gets the IP address of the caller.")]
        [WebMethod(BufferResponse = false, EnableSession = false)]
        public string GetIPAddress()
        {
            if ((null != base.Context) || (null != base.Context.Request) || (null != base.Context.Request.ServerVariables))
            {
                string returnValue = base.Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (string.IsNullOrEmpty(returnValue))
                    returnValue = base.Context.Request.ServerVariables["REMOTE_ADDR"];

                return returnValue;
            }

            return null;
        }
    }
}
